using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XQ.RequestOfficeSupplies.BLL.Common;
using XQ.RequestOfficeSupplies.DAL.DAL.Business;
using XQ.RequestOfficeSupplies.DAL.Model.Business;
using XQ.RequestOfficeSupplies.DAL.Model;
using XQ.RequestOfficeSupplies.DAL.Models;
using XQ.RequestOfficeSupplies.DAL;

namespace XQ.RequestOfficeSupplies.BLL.Business
{
    public class InventoryTransactionDetailBLL
    {
        InventoryTransactionDetailDal inventoryTransactionDetailDal = new InventoryTransactionDetailDal();

        public List<InventoryTransactionDetailReturnModel> GetList(InventoryTransactionDetailSearchModel ssm, Pagination page, TokenModel token)
        {
            return inventoryTransactionDetailDal.GetList(ssm, page, token);
        }

        public Guid SaveInventoryTransactionDetail(Inventory_Transaction_Detail inventoryTransactionDetail, TokenModel token)
        {
            Guid InventoryTransactionDetailID = inventoryTransactionDetail.id;
            bool isSuccess = false;
            DateTime curTime = DateTime.Now;
            if (inventoryTransactionDetail.id !=null)
            {
                isSuccess = inventoryTransactionDetailDal.UpdateModel(inventoryTransactionDetail) > 0;

            }
            else
            {
                //新增
                Inventory_Transaction_Detail inventoryTransactionDetailInfo = inventoryTransactionDetailDal.AddModel(inventoryTransactionDetail);
                InventoryTransactionDetailID = inventoryTransactionDetailInfo.id;

            }

            return InventoryTransactionDetailID;
        }

        public InventoryTransactionDetailReturnModel GetInventoryTransactionDetailByID(Guid id)
        {
            InventoryTransactionDetailReturnModel inventoryTransactionDetailModel = new InventoryTransactionDetailReturnModel();
            Inventory_Transaction_Detail inventoryTransactionDetail = inventoryTransactionDetailDal.FindModel(c => c.id == id);
            inventoryTransactionDetailModel = ClassHelper.ParentCopyToChild<Inventory_Transaction_Detail, InventoryTransactionDetailReturnModel>(inventoryTransactionDetail);

            return inventoryTransactionDetailModel;
        }


        public int DeleteByIds(List<Guid> ids)
        {
            return inventoryTransactionDetailDal.DeleteModel(c => ids.Contains(c.id));
        }
    }
}
